package org.lql.algo.codecrush.week008;

/**
 * @author: liangqinglong
 * @date: 2025-08-19 00:02
 * @description: 242. 有效的字母异位词 <a href="https://leetcode.cn/problems/valid-anagram/description/">...</a>
 **/
public class IsAnagram {

	public boolean isAnagram(String s, String t) {
		if (s.length() != t.length()) {
			return false;
		}
		int[] count = new int[26];
		for (int i = 0; i < s.length(); i++) {
			count[s.charAt(i) - 'a']++;
			count[t.charAt(i) - 'a']--;
		}
		for (int j : count) {
			if (j != 0) {
				return false;
			}
		}
		return true;
	}

	public static void main(String[] args) {
		String s = "anagram";
		String t = "nagaram";
		System.out.println(new IsAnagram().isAnagram(s, t));
		System.out.println(new IsAnagram().isAnagram("rat", "car"));
	}
}
